package com.nervenets.shopping.hibernate.dao;

import com.nervenets.general.hibernate.dao.BaseTreeDao;
import com.nervenets.shopping.hibernate.domain.user.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface UserDao extends BaseTreeDao<User> {
    User findByUnionId(String unionId);

    User findByMobile(String mobile);

    @Modifying
    @Transactional
    @Query("update User set inviteCount = :count where id = :id ")
    void updateInviteCount(@Param("count") long count, @Param("id") long id);

    @Modifying
    @Transactional
    @Query(value = "update User SET groupCount = :groupCount, lastGroupTime = :lastGroupTime where id = :id ")
    void updateGroupCountAndTime(@Param("id") long id, @Param("groupCount") long groupCount, @Param("lastGroupTime") long lastGroupTime);
}
